package com.lanyou.esb.cook.proxy.entity;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.lanyou.esb.cook.proxy.common.Constants;
import com.lanyou.esb.cook.proxy.meta.EnableType;

/**
 * 接口平均响应时间
 * 
 * @author Davey.wu
 */
public class IfAvgResTimes {
	/** ID **/
	private String id;
	/** 接口ID **/
	private String ifId;
	/** 平均响应时间 **/
	private float avgResTimes;
	/** 开始时间 **/
	private Date startDate;
	/** 时间间隔 **/
	private int interval;
	/** 时间间隔单位 **/
	private String intervalUnit;
	/** 是否可用 **/
	private String isEnable;
	/** 创建人 **/
	private String creator;
	/** 创建时间 **/
	private Date createDate;
	/** 最后更新人员 **/
	private String modifier;
	/** 最后更新时间 **/
	private Date lastUpDate;

	private static SimpleDateFormat dateFormat = new SimpleDateFormat(
			"yyyyMMddHH");

	public IfAvgResTimes() {
		// 设置标识为UUID
		this.id = UUID.randomUUID().toString().replace("-", "");
		// 默认为可用
		this.isEnable = EnableType.ENABLE.ValueCode;
	}

	public String getId() {
		return id;
	}

	public IfAvgResTimes setId(String id) {
		this.id = id;
		return this;
	}

	public String getIfId() {
		return ifId;
	}

	public IfAvgResTimes setIfId(String ifId) {
		this.ifId = ifId;
		return this;
	}

	public float getAvgResTimes() {
		return avgResTimes;
	}

	public IfAvgResTimes setAvgResTimes(float avgResTimes) {
		this.avgResTimes = avgResTimes;
		return this;
	}

	public Date getStartDate() {
		return startDate;
	}

	public IfAvgResTimes setStartDate(Date startDate) {
		this.startDate = startDate;
		return this;
	}

	public int getInterval() {
		return interval;
	}

	public IfAvgResTimes setInterval(int interval) {
		this.interval = interval;
		return this;
	}

	public String getIntervalUnit() {
		return intervalUnit;
	}

	public IfAvgResTimes setIntervalUnit(String intervalUnit) {
		this.intervalUnit = intervalUnit;
		return this;
	}

	public String getIsEnable() {
		return isEnable;
	}

	public IfAvgResTimes setIsEnable(String isEnable) {
		this.isEnable = isEnable;
		return this;
	}

	public String getCreator() {
		return StringUtils.isEmpty(creator) ? Constants.DEFAULT_USER : creator;
	}

	public IfAvgResTimes setCreator(String creator) {
		this.creator = creator;
		return this;
	}

	public Date getCreateDate() {
		return createDate == null ? new Date() : createDate;
	}

	public IfAvgResTimes setCreateDate(Date createDate) {
		this.createDate = createDate;
		return this;
	}

	public String getModifier() {
		return StringUtils.isEmpty(modifier) ? Constants.DEFAULT_USER
				: modifier;
	}

	public IfAvgResTimes setModifier(String modifier) {
		this.modifier = modifier;
		return this;
	}

	public Date getLastUpDate() {
		return lastUpDate;
	}

	public IfAvgResTimes setLastUpDate(Date lastUpDate) {
		this.lastUpDate = lastUpDate;
		return this;
	}

	@JsonIgnore
	public String getSection() {
		return dateFormat.format(this.startDate);
	}

	@JsonIgnore
	public String getNumKey() {
		return dateFormat.format(this.startDate);
	}

}